package rtsp

import (
	"net"
	"time"
	"xmediaEmu/pkg/decoder/codec"
	"xmediaEmu/pkg/format/rtsp/sdp"
)

// client 连接简单处理.
type connWithTimeout struct {
	Timeout time.Duration
	net.Conn
}

func (self connWithTimeout) Read(p []byte) (n int, err error) {
	if self.Timeout > 0 {
		self.Conn.SetReadDeadline(time.Now().Add(self.Timeout))
	}
	return self.Conn.Read(p)
}

func (self connWithTimeout) Write(p []byte) (n int, err error) {
	if self.Timeout > 0 {
		self.Conn.SetWriteDeadline(time.Now().Add(self.Timeout))
	}
	return self.Conn.Write(p)
}

// Stream rtsp stream
type Stream struct {
	codec.CodecData
	Sdp    sdp.Media
	client *Client

	// h264
	fuStarted  bool
	fuBuffer   []byte
	sps        []byte
	pps        []byte
	spsChanged bool
	ppsChanged bool

	gotpkt         bool
	pkt            codec.Packet
	timestamp      uint32
	firsttimestamp uint32

	lasttime time.Duration
}
